<% @page_title = "#{h @event.title} | 多背一公斤 - 灾后学校重建计划" %>

<% content_for :sidebar do -%>
  <% if logged_in? && @event.participators.include?(current_user) -%>
    <h2><%= link_to "上传活动中拍的照片", new_photo_url(:event_id => @event.id) %></h2>
  <% end -%>
  
  <% if @event.has_end? -%>
    <h2>活动已结束</h2>
  <% else -%>
    <% if logged_in? -%>
      <% unless @event.participators.include?(current_user) -%>
        <h2><%= link_to "参加这个活动", join_event_path(@event), :method => :put %></h2>
      <% else -%>
        <h2><%= link_to "退出活动", quit_event_path(@event), :method => :put %></h2>
      <% end -%>
    <% else -%>
      <p><%= link_to "登录", login_url %>后可以参加这个活动</p>
    <% end -%>
  <% end -%>
  
  <h2><%= link_to "返回活动首页", events_path %></h2>
  
  <h2 class="pink">谁参加这个活动 &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp;</h2>
  <%= render :partial => "/shared/users", :object => @event.participators %>
<% end -%>

<h1><%= h @event.title %></h1>
<h2>活动情况</h2>
<%= image_tag(@event.pic.public_filename, :style => "float:right; margin: 0 0 0 5px") if @event.pic %>
<p><label for="event_category">活动类型：</label><%= Event.categories[@event.category] %></p>
<p><label for="event_start_at">开始时间：</label><%= show_datetime(@event.start_at, false) %></p>
<p><label for="event_end_at">结束时间：</label><%= show_datetime(@event.end_at, false) %></p>
<p><label for="event_location">集合地点：</label><%= h @event.location %></p>
<p><label for="event_submitor">发布人：</label><%= link_to @event.submitor.login, user_path(@event.submitor.id) %></p>
<% unless @event.school_id.blank? -%>
  <p><label for="event_school">要去的学校：</label><%= link_to @event.school.title, school_url(@event.school_id) %></p>
<% end -%>
<p><label for="event_participators">参加人数：</label><%= @event.participators.count %></p>

<h2>活动内容</h2>
<%= @event.content_html %>

<% if @event.editable_by? current_user -%>
<p style="text-align:right;">
  <%= link_to "上传一张标题图片", new_pic_event_path(@event), :title => "传一张可以代表活动的图片可以更好的吸引用户参加，让你的活动更有吸引力" unless @event.pic %> | 
  <%  if @event.school_id.nil? -%>
    <%= link_to "选择要去的学校", choice_school_event_path(@event), :title => "选择活动中要去的学校，加入多背一公斤活动" %> |
  <% else -%>
    <%= link_to "重新选择要去的学校", choice_school_event_path(@event), :title => "修改活动中要去的学校" %> |
  <% end -%>
  <%= link_to "修改活动", edit_event_path(@event.id) %> 
  <%= link_to "删除", event_path(@event.id), :method => :delete, :confirm => "确定要删除么？" %></p>
<% end -%>

<h2>活动照片 &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp;</h2>
<% @photos.each do |photo| -%>
  <%= link_to image_tag(photo.public_filename(:small), :style => "border: 1px solid #666;padding:2px"), photo_url(photo) %>
<% end -%>

<h2>用户留言 &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp;</h2>
<% @comments.each do |cmt| -%>
  <div class="cmt-item" style="margin-bottom:10px">
    <div style="float:left;margin:0 8px 0 0">
      <%= avatar_for cmt.user, "large" %><br />
    </div>
    <div style="margin-left:50px">
      <div>
        <div style="background-color:#ffc"><h2><%= h cmt.title %></h2></div>
        
        <% if cmt.editable_by?(current_user) -%>
        <span style="float:right">
          <%= link_to "修改", event_edit_comment_path(@event, cmt) %>
          <%= link_to "删除", event_comment_path(@event, cmt), :method => 'delete', :confirm => "您确定要删除么？" %>
        </span>
        <% end -%>
        
        <%= link_to cmt.user.login, user_path(cmt.user) %><span class="tip"> 写于 <%= show_datetime cmt.created_at %></span>
      </div>
      <div><%= cmt.content_html %></div>
    </div>
  </div>
<% end -%>
<hr />
<% if logged_in? -%>
  <% form_for :comment, :url => event_comments_path(:event_id => @event.id) do |f| -%>
    <%= render :partial => 'event_comments/form', :object => f, :locals => {:title => "Re:#{@event.title}"} %>
    <p><%= submit_tag "发布评论" %></p>
  <% end -%>
<% else -%>
  <%= link_to "登录", login_url %>后你也可以发表评论或留言
<% end -%>